home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / gnu / gnulib / sipp / libsipp / bumpy.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-03  |  1.8 KB  |  69 lines

  1. /**
  2.  ** sipp - SImple Polygon Processor
  3.  **
  4.  **  A general 3d graphic package
  5.  **
  6.  **  Copyright Equivalent Software HB  1992
  7.  **
  8.  ** This program is free software; you can redistribute it and/or modify
  9.  ** it under the terms of the GNU General Public License as published by
  10.  ** the Free Software Foundation; either version 1, or any later version.
  11.  ** This program is distributed in the hope that it will be useful,
  12.  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  ** GNU General Public License for more details.
  15.  ** You can receive a copy of the GNU General Public License from the
  16.  ** Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  **/
  18.  
  19. /**
  20.  ** bumpy.c - Bumpy shader: simulates an bumpy surfaces using noise and Dnoise
  21.  **/
  22.  
  23. #include <math.h>
  24. #include <stdio.h>
  25.  
  26. #include <sipp.h>
  27. #include <geometric.h>
  28. #include <noise.h>
  29. #include <shaders.h>
  30.  
  31.  
  32. extern bool noise_ready;
  33.  
  34.  
  35. void
  36. bumpy_shader(pos, normal, texture, view_vec, lights, bd, color, opacity)
  37.     Vector      *pos;
  38.     Vector      *normal;
  39.     Vector      *texture;
  40.     Vector      *view_vec;
  41.     Lightsource *lights;
  42.     Bumpy_desc  *bd;
  43.     Color       *color;
  44.     Color       *opacity;
  45. {
  46.     Vector     tmp;
  47.     Vector     norm;
  48.     double     len;
  49.     double     no;
  50.  
  51.     if (!noise_ready) {
  52.         noise_init();
  53.     }
  54.  
  55.     VecCopy(norm, *normal);
  56.     vecnorm(&norm);
  57.     VecScalMul(tmp, bd->scale, *texture);
  58.  
  59.     if ((bd->bumpflag && bd->holeflag)
  60.           || ((no = noise(&tmp)) < 0.0 && bd->bumpflag)
  61.           || (no > 0.0 && bd->holeflag)) {
  62.         tmp = Dnoise(&tmp);
  63.         VecAdd(norm, norm, tmp);
  64.     }
  65.  
  66.     bd->shader(pos, &norm, texture, view_vec, lights, bd->surface, 
  67.                color, opacity);
  68. }
  69.